package com.tt.job.test;

import com.tt.job.api.JobContext;
import com.tt.job.api.JobMode;
import com.tt.job.api.JobParameterInfo;
import com.tt.job.api.JobResult;
import com.tt.job.api.log.JobLoggerFactory;
import com.tt.job.api.schedule.ScheduleType;
import com.tt.job.api.type.JobType;
import com.tt.job.api.type.simple.SimpleJob;
import com.tt.job.test.service.EchoJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * TODO info
 **/
@Service
public class EchoJob implements SimpleJob {

    @Autowired
    EchoJobService echoJobService;

    @Override
    public JobResult execute(JobContext jobContext) {
        System.out.println("singleton echo job");
        JobLoggerFactory.getThreadLogger().debug("debug: singleton echo job");
        JobLoggerFactory.getThreadLogger().error("error: singleton echo job");
        JobLoggerFactory.getThreadLogger().info("info: singleton echo job");
        echoJobService.echo(jobContext);
        return JobResult.SUCCESS;
    }

    @Override
    public String getDescription() {
        return "this is a job";
    }

    @Override
    public List<JobParameterInfo> getJobParameters() {
        return null;
    }

    @Override
    public Set<ScheduleType> getJobSupportScheduleType() {
        return ScheduleType.toSet(ScheduleType.TRIGGER);
    }

    @Override
    public JobMode getMode() {
        return JobMode.CONCURRENTLY;
    }

    @Override
    public String getName() {
        return "echoJob";
    }

    @Override
    public JobType getType() {
        return JobType.SIMPLE;
    }
}
